<template>
  <div class="big-box">
    <div class="search-container">
      <el-form
        :inline="true"
        label-width="100px"
        class="score"
        :data="ScoreList"
        ref="queryFormRef"
        :model="queryParams"
      >
        <el-form-item label="作文号" prop="workId">
          <el-input
            v-model="queryParams.workId"
            @keyup.enter="handleQuery"
            placeholder="作文号"
            clearable
            style="width: 200px; margin-right: 20px"
        /></el-form-item>
        <el-form-item class="handleQuery">
          <el-button type="primary" @click="handleQuery"
            ><i-ep-search />搜索</el-button
          >
          <el-button @click="resetQuery"><i-ep-refresh />重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-card shadow="never" class="table-container">
      <el-table
        v-loading="loading"
        highlight-current-row
        border
        :data="ScoreList"
        ref="ScoreFormRef"
      >
        <el-table-column
          label="作文号"
          prop="workId"
          width="200"
          align="center"
        />
        <!-- show-overflow-tooltip -->
        <el-table-column label="作文题目" align="center" prop="tile" />
        <el-table-column
          label="姓名"
          align="center"
          prop="username"
          width="200"
        />
        <el-table-column label="分数" align="center" prop="score" width="200" />
        <!-- <el-table-column fixed="right" label="操作" align="center" width="200">
          <template #default="">
            <el-button type="primary" link size="small"
              ><i-ep-view />写作</el-button
            >
            <el-button type="primary" link size="small"
              ><i-ep-delete />修改</el-button
            >
          </template>
        </el-table-column> -->
      </el-table>

      <pagination
        v-if="total > 0"
        v-model:total="total"
        v-model:page="queryParams.page"
        v-model:limit="queryParams.pageSize"
        @pagination="handleQuery"
      />
    </el-card>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { getScoreComPage } from "@/api/composition/score/index";
import {
  ScoreComForms,
  ScoreComQuery,
  ScoreComPageVO,
  ScoreComPageResult,
} from "@/api/composition/score/types";

const value = ref();
// const channelList = ref([]);
const editDialog = ref();
const removeIds = ref([]); // 删除用户ID集合 用于批量删除
// const removeId = ref([]); // 删除用户ID集合 用于批量删除
const loading = ref(false);
const ScoreList = ref<ScoreComPageVO[]>();
const userList = ref<UserPageVO[]>();
const total = ref(0);
const queryFormRef = ref(ElForm);
const queryParams = reactive<ScoreComQuery>({
  page: 1,
  pageSize: 10,
});
const UserPageVOs = reactive<UserPageVO>({});

/** 查询 */
function handleQuery() {
  loading.value = true;
  getScoreComPage(queryParams)
    .then(({ data }) => {
      ScoreList.value = data.items;
      total.value = data.total;
    })
    .finally(() => {
      loading.value = false;
    });
}
/** 重置查询 */
function resetQuery() {
  queryFormRef.value.resetFields();
  queryParams.page = 1;
  handleQuery();
}

onMounted(() => {
  handleQuery();
});

const ScoreFormRef = ref(ElForm);

const formData = reactive<ScoreComForms>({
  id: "",
  username: "",
  workId: "",
  content: "",
  tile: "",
});
/** 关闭新增修改表单弹窗 */
function closeDialogs() {
  dialog.visible = false;
  resetForm();
}

/** 重置表单 */
function resetForm() {
  ScoreFormRef.value.resetFields();
  ScoreFormRef.value.clearValidate();

  formData.id = "";
  formData.username = "";
  formData.workId = "";
  formData.content = "";
  formData.tile = "";
}

// const dialog = reactive({
//   title: "",
//   visible: false,
// });

// /** 打开修改增加表单弹窗 */
// function openDialog(workId?: string) {
//   dialog.visible = true;
//   // console.log(id.id);
//   console.log(workId.workId);
//   // const ID = id.id;
//   const ID = workId.workId;
//   if (ID) {
//     dialog.title = "修改作文内容";
//     getStudentComMenuIds(ID).then(({ data }) => {
//       Object.assign(formData, data);
//     });
//   } else {
//     dialog.title = "写作";
//   }
// }

// /** 新增修改保存提交 */
// function handleSubmit() {
//   StudentFormRef.value.validate((valid: any) => {
//     if (valid) {
//       loading.value = true;
//       const StudentId = formData.id;
//       if (StudentId) {
//         ElMessageBox.confirm("确认修改?", "警告", {
//           confirmButtonText: "确定",
//           cancelButtonText: "取消",
//           type: "warning",
//         }).then(() => {
//           updateStudentCom(StudentId, formData)
//             .then(() => {
//               ElMessage.success("修改成功");
//               closeDialogs();
//               resetQuery();
//             })
//             .finally(() => (loading.value = false));
//         });
//       } else {
//         ElMessageBox.confirm("确认增加?", "警告", {
//           confirmButtonText: "确定",
//           cancelButtonText: "取消",
//           type: "warning",
//         }).then(() => {
//           addStudentCom(formData)
//             .then(() => {
//               ElMessage.success("新增成功");
//               closeDialogs();
//               resetQuery();
//             })
//             .finally(() => (loading.value = false));
//         });
//       }
//     }
//   });
// }
</script>

<style scoped lang="scss">
.form-container {
  display: flex;
  flex-wrap: wrap;
}

.handleQuery {
  margin-left: auto;
}
</style>
